<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}地标和路径管理系统{% endblock %}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-color: #4e73df;
            --secondary-color: #858796;
            --success-color: #1cc88a;
            --info-color: #36b9cc;
            --warning-color: #f6c23e;
            --danger-color: #e74a3b;
            --light-color: #f8f9fc;
            --dark-color: #5a5c69;
            --sidebar-width: 250px;
        }

        * {
            font-family: 'Noto Sans SC', sans-serif;
        }

        body {
            background-color: var(--light-color);
            color: var(--dark-color);
        }

        .navbar {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 101;
            background-color: var(--primary-color) !important;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
        }

        .navbar-brand {
            font-weight: 700;
            font-size: 1.2rem;
        }

        .sidebar {
            height: 100vh;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 100;
            padding-top: 56px;
            width: var(--sidebar-width);
            background-color: var(--primary-color);
            background-image: linear-gradient(180deg, #4e73df 10%, #224abe 100%);
            background-size: cover;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
            transition: all 0.3s;
        }

        .content {
            margin-left: var(--sidebar-width);
            padding: 20px;
            transition: all 0.3s;
            min-height: 100vh;
        }

        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.8);
            border-radius: 0.35rem;
            margin: 0.2rem 0;
            padding: 0.75rem 1rem;
            font-weight: 400;
            transition: all 0.3s;
        }

        .sidebar .nav-link:hover {
            color: #fff;
            background-color: rgba(255, 255, 255, 0.1);
        }

        .sidebar .nav-link.active {
            color: #fff;
            background-color: rgba(255, 255, 255, 0.2);
            font-weight: 700;
        }

        .sidebar .nav-link i {
            margin-right: 0.5rem;
            width: 1.25rem;
            text-align: center;
        }

        .card {
            border: none;
            border-radius: 0.35rem;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
            margin-bottom: 1.5rem;
            transition: all 0.3s;
        }

        .card:hover {
            box-shadow: 0 0.25rem 2rem 0 rgba(58, 59, 69, 0.2);
        }

        .card-header {
            background-color: #f8f9fc;
            border-bottom: 1px solid #e3e6f0;
            font-weight: 700;
            color: var(--primary-color);
        }

        .btn {
            border-radius: 0.35rem;
            font-weight: 500;
            padding: 0.375rem 0.75rem;
            transition: all 0.3s;
        }

        .btn-primary {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }

        .btn-primary:hover {
            background-color: #2e59d9;
            border-color: #2653d4;
        }

        .btn-success {
            background-color: var(--success-color);
            border-color: var(--success-color);
        }

        .btn-danger {
            background-color: var(--danger-color);
            border-color: var(--danger-color);
        }

        .table {
            color: var(--dark-color);
        }

        .table thead th {
            border-bottom: 2px solid #e3e6f0;
            font-weight: 700;
            color: var(--primary-color);
        }

        .preview-image {
            max-width: 100px;
            max-height: 100px;
            object-fit: cover;
            border-radius: 0.25rem;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            transition: all 0.3s;
        }

        .preview-image:hover {
            transform: scale(1.05);
            box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.15);
        }

        .media-item {
            position: relative;
            display: inline-block;
            margin-right: 10px;
            margin-bottom: 10px;
            border-radius: 0.25rem;
            overflow: hidden;
            transition: all 0.3s;
        }

        .media-item:hover {
            transform: translateY(-3px);
        }

        .media-remove {
            position: absolute;
            top: 5px;
            right: 5px;
            background: rgba(255, 255, 255, 0.9);
            border-radius: 50%;
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            color: var(--danger-color);
            transition: all 0.3s;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
        }

        .media-remove:hover {
            background: var(--danger-color);
            color: white;
            transform: rotate(90deg);
        }

        .form-control, .form-select {
            border-radius: 0.35rem;
            border: 1px solid #d1d3e2;
            transition: all 0.3s;
        }

        .form-control:focus, .form-select:focus {
            border-color: #bac8f3;
            box-shadow: 0 0 0 0.25rem rgba(78, 115, 223, 0.25);
        }

        .list-group-item {
            border-radius: 0.35rem;
            margin-bottom: 0.25rem;
            border: 1px solid #e3e6f0;
            transition: all 0.3s;
        }

        .list-group-item:hover {
            background-color: #f8f9fc;
            transform: translateX(5px);
        }

        .badge {
            padding: 0.35em 0.65em;
            font-weight: 500;
            border-radius: 0.35rem;
        }

        .page-title {
            font-weight: 700;
            color: var(--primary-color);
            margin-bottom: 1rem;
        }

        .stats-card {
            border-left: 0.25rem solid;
            transition: all 0.3s;
        }

        .stats-card:hover {
            transform: translateY(-5px);
        }

        .stats-card.primary {
            border-left-color: var(--primary-color);
        }

        .stats-card.success {
            border-left-color: var(--success-color);
        }

        .stats-card.info {
            border-left-color: var(--info-color);
        }

        .stats-card.warning {
            border-left-color: var(--warning-color);
        }

        .stats-card .card-body {
            padding: 1rem;
        }

        .stats-card .stats-icon {
            font-size: 2rem;
            opacity: 0.4;
        }

        .stats-card.primary .stats-icon {
            color: var(--primary-color);
        }

        .stats-card.success .stats-icon {
            color: var(--success-color);
        }

        .stats-card.info .stats-icon {
            color: var(--info-color);
        }

        .stats-card.warning .stats-icon {
            color: var(--warning-color);
        }

        @media (max-width: 768px) {
            .sidebar {
                width: 0;
                overflow: hidden;
            }

            .sidebar.show {
                width: var(--sidebar-width);
            }

            .content {
                margin-left: 0;
            }

            .navbar-toggler {
                display: inline-block;
            }
        }
    </style>
    {% block extra_css %}{% endblock %}
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container-fluid">
            <button class="navbar-toggler d-md-none" type="button" id="sidebar-toggle">
                <span class="navbar-toggler-icon"></span>
            </button>
            <a class="navbar-brand" href="/admin">
                <i class="bi bi-geo-alt-fill me-2"></i>地标和路径管理系统
            </a>
            <div class="collapse navbar-collapse">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="bi bi-person-circle me-1"></i>{% if user %}{{ user.full_name or user.username }}{% else %}管理员{% endif %}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                            <li><a class="dropdown-item" href="#"><i class="bi bi-gear me-2"></i>设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="/logout"><i class="bi bi-box-arrow-right me-2"></i>退出</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="sidebar" id="sidebar">
        <div class="d-flex flex-column p-3">
            <ul class="nav nav-pills flex-column mb-auto">
                <li class="nav-item">
                    <a href="/admin" class="nav-link {% if request.url.path == '/admin' %}active{% endif %}">
                        <i class="bi bi-speedometer2 me-2"></i>控制台
                    </a>
                </li>
                <li class="nav-item">
                    <a href="/admin/landmarks" class="nav-link {% if 'landmarks' in request.url.path and 'create' not in request.url.path and request.url.path|length <= 20 %}active{% endif %}">
                        <i class="bi bi-geo-alt me-2"></i>地标管理
                    </a>
                </li>
                <li class="nav-item">
                    <a href="/admin/routes" class="nav-link {% if 'routes' in request.url.path and 'create' not in request.url.path and request.url.path|length <= 17 %}active{% endif %}">
                        <i class="bi bi-route me-2"></i>路径管理
                    </a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownCreate" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        <i class="bi bi-plus-circle me-2"></i>快速创建
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="navbarDropdownCreate">
                        <li><a class="dropdown-item" href="/admin/landmarks/create"><i class="bi bi-geo-alt me-2"></i>创建地标</a></li>
                        <li><a class="dropdown-item" href="/admin/routes/create"><i class="bi bi-route me-2"></i>创建路径</a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="/admin/api-docs" class="nav-link {% if request.url.path == '/admin/api-docs' %}active{% endif %}">
                        <i class="bi bi-code-square me-2"></i>API文档
                    </a>
                </li>
                <li class="nav-item mt-3">
                    <a class="nav-link disabled text-light opacity-50" href="#">
                        <i class="bi bi-gear me-2"></i>系统设置
                    </a>
                </li>
            </ul>
            <div class="mt-auto text-center text-white-50">
                <small>地标和路径管理系统 v1.0</small>
            </div>
        </div>
    </div>

    <div class="content" id="content">
        {% block content %}{% endblock %}
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        // 设置全局AJAX默认值，添加认证头
        $.ajaxSetup({
            beforeSend: function(xhr) {
                // 从localStorage获取令牌
                const token = localStorage.getItem('access_token');
                if (token) {
                    xhr.setRequestHeader('Authorization', 'Bearer ' + token);
                }
            }
        });

        // 移动端侧边栏切换
        document.getElementById('sidebar-toggle').addEventListener('click', function() {
            document.getElementById('sidebar').classList.toggle('show');
        });

        // 点击内容区域时，在移动端关闭侧边栏
        document.getElementById('content').addEventListener('click', function() {
            if (window.innerWidth < 768) {
                document.getElementById('sidebar').classList.remove('show');
            }
        });
    </script>
    {% block extra_js %}{% endblock %}
</body>
</html>
